<?php

namespace app\common\model\jiyun\warehouse;

use think\admin\Model;

/**
 * 仓库货位
 * @package app\common\model\company\warehouse_center;
 * @author  shirrukun
 * @date 2024/11/25
 */
class WarehouseRegionLocationModel extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'jiyun_warehouse_region_location';

    /**
     * 日志名称
     * @var string
     */
    protected $oplogName = '仓库货位';

    /**
     * 日志类型
     * @var string
     */
    protected $oplogType = '仓库货位管理';

    /**
     * 货位状态
     * @var array
     * */
    public static function LOCATION_STATUS_SB()
    {
        return [
            20 => lang("启用"),
            10 => lang("禁用"),
        ];

    }

    /**
     * 货架类型
     * @var array
     * */
    public static function SHELVES_TYPE_SB()
    {
        return [
            10 => lang("小货架"),
            20 => lang("大货架"),
        ];
    }

    /**
     * 货区状态
     * */
    public function getStatusAttr($value,$data){
        $status = self::LOCATION_STATUS_SB();
        return !empty($status[$value]) ? $status[$value] : lang("数据异常");
    }

    /**
     * 关联绑定仓库名称
     * */
    public function warehouseName()
    {
        return $this->belongsTo(WarehouseModel::class,'warehouse_id')->bind(['warehouse_c_name']);
    }

    /**
     * 获取货位编码列表
     * @param $company_id
     * @return array
     * */
    public static function getLocationList($company_id): array
    {
        return self::mk()->where(['account_id'=>$company_id,'status'=>20])->column('location_code', 'id');
    }
}